package com.iven.xie.es.service;

import com.iven.xie.es.entity.EsEntity;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.search.builder.SearchSourceBuilder;

import java.util.List;

/**
 * @author iven.xie
 * @version 1.0
 * @date 2020/02/28 18:15
 */
public interface BaseSearchService<T> {

    /**
     * 初始化
     */
    void init();

    /**
     * 初始化指定索引
     *
     * @param indexName 索引
     */
    void initIndex(String indexName);

    /**
     * Description: 判断某个index是否存在
     *
     * @param index index名
     * @return boolean
     * @throws Exception 异常
     */
    boolean indexExist(String index) throws Exception;

    /**
     * Description: 删除index
     *
     * @param index index
     * @return void
     */
    void deleteIndex(String index);

    /**
     * Description: 插入/更新一条记录
     *
     * @param index  index
     * @param entity 对象
     */
    void insertOrUpdateOne(String index, EsEntity entity);

    /**
     * Description: 批量插入数据
     *
     * @param index index
     * @param list  带插入列表
     */
    void insertBatch(String index, List<EsEntity> list);

    /**
     * Description: delete by query
     *
     * @param index   index
     * @param builder builder
     */
    void deleteByQuery(String index, QueryBuilder builder);

    /**
     * Description: 搜索
     *
     * @param index   index
     * @param builder 查询参数
     * @param c       结果类对象
     * @return java.util.ArrayList
     */
    <T> List<T> search(String index, SearchSourceBuilder builder, Class<T> c);
}
